<!DOCTYPE html>
<html lang="en"
      xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
<head>
    <meta charset="UTF-8">
    <title>图书管理系统</title>
    <script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
    <style>
        nav {
            font-size: 1.5rem;
            background-color: #21D4FD;
            background-image: -webkit-linear-gradient(19deg, #21D4FD 0%, #B721FF 100%);
            background-image: -moz-linear-gradient(19deg, #21D4FD 0%, #B721FF 100%);
            background-image: -o-linear-gradient(19deg, #21D4FD 0%, #B721FF 100%);
            background-image: linear-gradient(19deg, #21D4FD 0%, #B721FF 100%);
        }
        h1 {
            font-size: 2rem;
            color: white;
        }
        li {
            margin: 10px 20px;
        }
        th {
            width: 100px;
        }
        label {
            margin: auto;
            padding-right: 20px;
        }
        .input-group {
            margin-bottom: 10px;
        }
    </style>
    <script>
        function a1() {
            $.post({
                url:"/admin/user/checkPassword",
                data:{'pwd':$("#oldPassword").val()},
                success:function (data) {
                    if(data.toString() === 'true'){
                        $("#oldPassword").removeClass("is-invalid");
                        $("#oldPassword").addClass("is-valid");
                        $("#errorPwd").hide();
                    }else {
                        $("#oldPassword").removeClass("is-valid");
                        $("#oldPassword").addClass("is-invalid");
                        $("#errorPwd").show();
                    }
                }
            });

        }

        function a2() {
            if ($("#newPassword").val() == '') {
                $("#newPassword").removeClass("is-valid");
                $("#newPassword").addClass("is-invalid");
                $("#emptyPwd").show();
            } else {
                $("#newPassword").removeClass("is-invalid");
                $("#newPassword").addClass("is-valid");
                $("#emptyPwd").hide();
            }
            if ($("#checkPassword").val() != $("#newPassword").val()) {
                $("#checkPassword").removeClass("is-valid");
                $("#checkPassword").addClass("is-invalid");
                $("#errorChecked").show();
            } else {
                if ($("#checkPassword").val() == '') {
                    $("#checkPassword").removeClass("is-valid");
                    $("#checkPassword").removeClass("is-invalid");
                    $("#errorChecked").hide();
                } else {
                    $("#checkPassword").removeClass("is-invalid");
                    $("#checkPassword").addClass("is-valid");
                    $("#errorChecked").hide();
                }
            }
        }

        function a3() {
            if ($("#checkPassword").val() != $("#newPassword").val()) {
                $("#checkPassword").removeClass("is-valid");
                $("#checkPassword").addClass("is-invalid");
                $("#errorChecked").show();
            } else {
                if ($("#checkPassword").val() == '') {
                    $("#checkPassword").removeClass("is-valid");
                    $("#checkPassword").removeClass("is-invalid");
                    $("#errorChecked").hide();
                } else {
                    $("#checkPassword").removeClass("is-invalid");
                    $("#checkPassword").addClass("is-valid");
                    $("#errorChecked").hide();
                }
            }
        }
    </script>
</head>
<body>
<!--导航栏替换-->
<div th:replace="~{commons/commons :: topbar(active='index.html')}"></div>

<div class="container">
    <form th:action="@{'/admin/user/changePassword/' + ${session.username}}" method="post" style="margin-top: 40px" class="form">
        <div class="input-group">
            <label for="oldPassword">旧&nbsp;密&nbsp;码</label>
            <input type="text" class="form-control" id="oldPassword" name="oldPassword" onblur="a1()">
            <span class="invalid-feedback" id="errorPwd" style="display: none">
                密码错误！
            </span>
        </div>
        <div class="input-group">
            <label for="newPassword">新&nbsp;密&nbsp;码</label>
            <input type="text" class="form-control" id="newPassword" name="newPassword" onblur="a2()">
            <span class="invalid-feedback" id="emptyPwd" style="display: none">
                密码不能为空！
            </span>
        </div>
        <div class="input-group">
            <label for="checkPassword">确认密码</label>
            <input type="text" class="form-control" id="checkPassword" name="checkPassword" onblur="a3()">
            <span class="invalid-feedback" id="errorChecked" style="display: none">
                两次输入密码不一致！
            </span>
        </div>
        <span th:text="${msg}" style="color:green"></span>
        <br>
        <input type="submit" value="修    改" class="btn btn-outline-primary btn-lg" style="margin-top: 20px">
        <a th:href="@{/index}" class="btn btn-outline-secondary btn-lg" style="margin-left: 40px; margin-top: 20px">返&nbsp;&nbsp;&nbsp;&nbsp;回</a>
    </form>
</div>

<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>

</body>
</html>